package cn.dt70.service.impl;

import cn.dt70.dao.aqbBankcard.AqbBankcardMapper;
import cn.dt70.pojo.AqbBankcard;
import cn.dt70.service.AqbBankcardService;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service("aqbBankcardService")
public class AqbBankcardServiceImpl implements AqbBankcardService {

    private static final Logger LOGGER = Logger.getLogger(AqbBankcardServiceImpl.class);

    @Resource
    private AqbBankcardMapper aqbBankcardMapper;

    @Override
    public boolean addCard(AqbBankcard aqbBankcard) {
        int row = 0;
        try {
            row = aqbBankcardMapper.saveCard(aqbBankcard);
            if (row != 1) {
                LOGGER.debug("aqbBankcardMapper.saveCard 添加失败");
            } else {
                LOGGER.debug("aqbBankcardMapper.saveCard 添加成功");
            }
        } catch (Exception e) {
            LOGGER.debug("aqbBankcardMapper.saveCard 添加异常" + e.getMessage());
        }
        return false;
    }

    @Override
    public AqbBankcard findByUserId(String userId) {
        AqbBankcard aqbBankcard = null;
        try {
            aqbBankcard = aqbBankcardMapper.selectByUserId(userId);
        } catch (Exception e) {
            LOGGER.error("aqbBankcardMapper.findByUserId 查找异常" + e.getMessage());
        }
        return aqbBankcard;
    }

    @Override
    public boolean modifyBankMoney(String userId, double balance) {
        boolean isPass = false;
        int row = 0;
        try {
            row = aqbBankcardMapper.updateByUserIdForBalance(userId, balance);
            if (row != 1) {
                LOGGER.debug("aqbBankcardMapper.modifyBankMoney 修改失败");
            } else {
                LOGGER.debug("aqbBankcardMapper.modifyBankMoney 修改成功");
                isPass = true;
            }
        } catch (Exception e) {
            LOGGER.error("aqbBankcardMapper.modifyBankMoney 修改异常" + e.getMessage());
        }
        return isPass;
    }
}
